#!/usr/bin/bash

# Make doc
cargo clean
cargo doc --no-deps --all-features

# Make temporary folder
rm -rf .doc_tmp
mkdir .doc_tmp
cd .doc_tmp

# initialize git repository
git init

# add remote
git remote add origin git@github.com:argmin-rs/argmin.git

# checkout gh-pages
git checkout -b gh-pages

# pull stuff
git pull origin gh-pages

# cleanup old stuff
rm -rf *

# copy documentation
cp -r ../target/doc/* .
touch .nojekyll
cat <<EOF > index.html
<!doctype html>
<meta http-equiv="refresh" content="0; ./argmin/">
EOF

# add and commit all
git add -f --all .
git add -f --all .*
git commit -m 'Semiautomatic update of documentation'

# push
git push -f origin gh-pages

# remove temporary directory
cd ..
rm -rf .doc_tmp
